package com.huaao.micropolice.core.model.system;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import com.huaao.micropolice.core.model.content.Subject;

/**
 * @author qiyang
 * 区域
 * @version 1.0
 */
public class Area implements Serializable{
	public static final Integer LEAF_YES=1;
	public static final Integer LEAF_NO=0;
	private String id;
	private String name;
	private String code;
	private String mark;
	private Integer level;
	private Integer isLeaf;
	private AreaType type = AreaType.shi;
	
	private Area parent;
	private Set<Area> children = new LinkedHashSet<Area>();
	
	
	public static enum AreaType {
        sheng("省"), shi("市"),qu("区"),jiedao("街道");

        private final String info;
        private AreaType(String info) {
            this.info = info;
        }

        public String getInfo() {
            return info;
        }
    }

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public AreaType getType() {
		return type;
	}

	public void setType(AreaType type) {
		this.type = type;
	}

	public Area getParent() {
		return parent;
	}

	public void setParent(Area parent) {
		this.parent = parent;
	}

	public Set<Area> getChildren() {
		return children;
	}

	public void setChildren(Set<Area> children) {
		this.children = children;
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public String getParentCode() {
		if(parent != null){
			return parent.getCode();
		}
		return null;
	}
	
	public String getParentName() {
		if(parent != null){
			return parent.getName();
		}
		return null;
	}
	
	public String getState(){
		if(children == null || children.size() == 0){
			return "open";  
		}else{
			return "closed";
		}
	}
	
	public void setParentId(String pid){
		Area area = new Area();
		area.setId(pid);
		this.setParent(area);
	}

	public String getParentId(){
		if(parent != null){
			return parent.getId();
		}
		return null;
	}
	
	public Integer getIsLeaf() {
		if(this.isLeaf == null){
			this.isLeaf = 0;
		}
		return isLeaf;
	}

	public void setIsLeaf(Integer isLeaf) {
		this.isLeaf = isLeaf;
	}
	
	public String getIsLeafName(){
		return this.isLeaf == 0? "false":"true";
	}
	
	
}
